/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.compare');
(function () {
		
	/**
	 * Panel to display Inventory information
	 * @class InventoryInfoPanel
	 * @extends Ext.Component
	 * @namespace net.autodata.compare
	 */
	var Panel = Ext.extend(Ext.Component, {
		
		autoEl: {
			tag: 'div',
			cls: 'inventoryInfo-panel'
		},
		
		/**
		 * @property view
		 * @type Object
		 */
		view: undefined,
		
		/**
		 * View configuration properties
		 * @property viewCfg
		 * @type Object
		 */
		viewCfg: undefined,
		
		/**
		 * @property inventoryRecord
		 * @type Object
		 */
		inventoryRecord: undefined,
		
		handler: undefined,
		
		constructor: function ()
		{	
			this.addEvents({
				'update': true,
				'click': true
			})
			Panel.superclass.constructor.apply(this, arguments);
		},
		
		/**
		 * @method initComponent
		 */
		initComponent: function ()
		{
			Panel.superclass.initComponent.apply(this, arguments);
			var view = this.getView();
			view.init(this);
		},
		
		/**
		 * @method getView
		 * @returns Object
		 */
		getView: function ()
		{
			if (!this.view) {
				this.view = new net.autodata.compare.InventoryInfoView(this.viewCfg);
			}
			
			return this.view;
		},
		
		/**
		 * @method getInventoryRecord
		 * @returns Object
		 */
		getInventoryRecord: function ()
		{
			return this.inventoryRecord;
		},
		
		/**
		 * @method setInventoryRecord
		 * @param {Object} record
		 */
		setInventoryRecord: function (record) 
		{
			this.inventoryRecord = record;
			this.fireEvent('update');
		},
		
		/**
		 * @method render
		 */
		render: function ()
		{
			Panel.superclass.render.apply(this, arguments);
			
			this.mon(this.el, {
				scope: this,
				'click': this.onClick
			});
			
			var view = this.getView();
			view.render();
		},
		
		onClick: function (e)
		{
			if (e) {
        		e.preventDefault();
        	}
        	
        	if(e.button !== 0){
                return;
            }
        	
        	this.fireEvent('click', this, e);
        	
        	if (this.handler) {
        		this.handler.call(this.scope || this, this, e);
        	} 
		}
	});
	
	net.autodata.compare.InventoryInfoPanel = Panel;	
})();